//通过高德获得定位
export default function getLocation(val){
    /* AMap.plugin('AMap.CitySearch', function () {
    var citySearch = new AMap.CitySearch()
    citySearch.getLocalCity(function (status, result) {
        if (status === 'complete' && result.info === 'OK') {
        // 查询成功，result即为当前所在城市信息
            location.value = result.city
        }
    })
    }) */

    AMap.plugin('AMap.Geolocation', function () {
    const geolocation = new AMap.Geolocation({
        enableHighAccuracy: true,//是否使用高精度定位，默认:true
        timeout: 10000,          //超过10秒后停止定位，默认：无穷大
        convert: false,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
    });
    geolocation.getCurrentPosition();
    AMap.event.addListener(geolocation, 'complete', data => {
        val.value =data.addressComponent.city+ data.addressComponent.district
    });//返回定位信息
    AMap.event.addListener(geolocation, 'error', data => console.log(1));      //返回定位出错信息
    });
}